﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LogManager.Base;
using LogManager.Base.Data;
using MvcContrib.Pagination;
using MvcContrib.Sorting;
using MvcContrib.UI.Grid;
using LogManager.ViewModels;

namespace LogManager.Controllers
{
    public class ImportController : BaseController
    {
        private ILogService _logService;
        private IEventService _eventService;

        /// <summary>
        /// Create new import controller
        /// </summary>
        /// <param name="logService">Log service</param>
        /// <param name="eventService">Event service</param>
        public ImportController(ILogService logService, IEventService eventService)
        {
            //Assign services
            _logService = logService;
            _eventService = eventService;
        }

        /// <summary>
        /// Overview over the last imports made
        /// </summary>
        /// <returns>Overview for imports</returns>
        public ActionResult Index()
        {    
            return View();
        }

        /// <summary>
        /// Get imports
        /// </summary>
        /// <param name="sortOptions">Sort options for the imports</param>
        /// <param name="page">Pagenumber</param>
        /// <param name="count">Number of items per page</param>
        /// <returns>List of imports</returns>
        public ActionResult List(GridSortOptions sortOptions, int page = 1, int count = 20)
        {
            var model = new ImportList
            {
                Imports = _eventService.GetImports().ToList().OrderBy(sortOptions.Column, sortOptions.Direction).AsPagination(page, count),
                SortOptions = sortOptions,
            };

            return PartialView(model);
        }
    }
}
